require 'rubygems'
gem 'fxruby'
require 'fox16'

include Fox
module Evil

  module Color
    WHITE = FXRGB(255, 255, 255) 
    BLACK = FXRGB(0, 0, 0) 
    GREEN = FXRGB(0, 255, 0)
    RED = FXRGB(255, 0, 0)
  end

  class LogDialog < FXDialogBox
    include Color

    def initialize(owner)
      super(owner, "Log Dialog", DECOR_ALL, 0, 0, 800, 400)
      contents = FXHorizontalFrame.new(self,
                                       LAYOUT_SIDE_TOP|FRAME_LINE|LAYOUT_FILL_X|LAYOUT_FILL_Y|PACK_UNIFORM_WIDTH)
      @log_text = FXText.new(contents, nil, 0, 
                             TEXT_READONLY|TEXT_WORDWRAP|TEXT_AUTOSCROLL|LAYOUT_FILL_X|LAYOUT_FILL_Y) 
      self.backColor = contents.backColor = @log_text.backColor = BLACK
      contents.borderColor = @log_text.textColor = WHITE
      create
      show
    end

    def append(log)
      @log_text.appendText log
      @log_text.makePositionVisible(@log_text.getBottomLine)
    end

    def text_color= (color)
      @log_text.textColor = color
    end
  end

  class Window
    def main_loop
      @ui_app = FXApp.new
      @main_window = FXMainWindow.new(@ui_app, "evil editor")
      @ui_app.create
      @ui_app.run
    end

    def query(title, question)
      FXInputDialog.getString('', @main_window, title, question)
    end

    def log_dialog
      LogDialog.new(@main_window)
    end
  end
end
